//
//  TabBarViewController.swift
//  CosClub
//
//  Created by 沙睿 on 2020/2/2.
//  Copyright © 2020 ios. All rights reserved.
//

import UIKit

open class BaseTabBarViewController: UITabBarController {
    
    public struct vcInfo {
        var image :String
        var vc :UIViewController
        public init(image :String,vc :UIViewController) {
            self.image = image
            self.vc = vc
        }
    }

    open override func viewDidLoad() {
        super.viewDidLoad()
        delegate = self
        vcInfoArray.forEach {
            let na = NavigationViewController.init(rootViewController: $0.vc)
            na.tabBarItem.image = UIImage.imageFromBasis(named: "tab_\($0.image)_default")
            na.tabBarItem.selectedImage = UIImage.imageFromBasis(named: "tab_\($0.image)_selected")
            self.addChild(na)
        }
        
    }
    

    
    open lazy var vcInfoArray: Array<vcInfo> = [
//        vcInfo.init(image: "home" ,vc: HomeViewController()),
//        vcInfo.init(image: "club", vc: PlayListViewController()),
//        vcInfo.init(image: "mine", vc: MineViewController())
    ];
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destination.
     // Pass the selected object to the new view controller.
     }
     */
    
    
}

extension BaseTabBarViewController {
    public var height :CGFloat{
        return self.tabBar.bounds.size.height
    }
}

extension BaseTabBarViewController : UITabBarControllerDelegate{
    public func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool
    {
//        if let nav = viewController as? NavigationViewController {
//            if nav.children.first is MineViewController &&
//                LoginInformation.shared.token?.count ?? 0 <= 0 {
//                viewController.present(LoginNavigationViewController(), animated: true, completion: nil)
//                return false
//            }
//        }
        
        return true
    }
}
